<template>
  <div class="page">
    <div class="top">
      <img src="../assets/avater.png" alt="头像" />
      <div>{{ userInfo.name }}</div>
    </div>
    <div class="content">
      <div class="tab-list">
        <div
          class="tab-item"
          :class="{ active: navChoose === item.value }"
          v-for="item in navList"
          :key="item.id"
          @click="handleClickNav(item.value)"
        >
          <div class="text">
            {{ item.title }}
          </div>
        </div>
      </div>

      <div class="card-list">
        <div
          class="card"
          v-for="(item, index) in articleList"
          :key="item.id"
          @click="handleClickArticleItem(item.id)"
        >
          <div class="card-image">
            <img
              class="card-img-top"
              src="../assets/gptAvatar.svg"
              alt="头像"
            />
          </div>

          <div
            class="card-content"
            :class="{ success: index % 3 == 1, primary: index % 3 == 2 }"
          >
            <h5 class="card-title">{{ item.title }}</h5>
            <p class="card-text">{{ item.date }}</p>
          </div>
        </div>
      </div>
    </div>
    <el-dialog :visible.sync="visible.essay" :title="dialogInfo.essay.title">
      <el-input
        v-model="dialogInfo.essay.content"
        autosize
        type="textarea"
      ></el-input>
      <template #footer>
        {{ dialogInfo.essay.date }}
      </template>
    </el-dialog>
  </div>
</template>

<script>
import * as TOOLS_DATE from "@/tools/date";

export default {
  data() {
    return {
      userInfo: {},
      chatList: [],
      articleList: [],
      navChoose: 0,
      navList: [
        {
          title: "创作记录",
          value: 0,
        },
      ],
      visible: {
        essay: false,
      },
      dialogInfo: {
        essay: {},
      },
    };
  },
  mounted() {
    this.init();
  },
  methods: {
    init() {
      this.userInfo = JSON.parse(localStorage.getItem("userInfo"));
      this.getArticle();
      this.getChatList();
    },
    getArticle() {
      const uid = JSON.parse(localStorage.getItem("userInfo")).uid;
      this.$axios.post("/getArticle", { uid }).then((res) => {
        if (res.data.code === 200) {
          const list = Array.from(res.data.data);
          list.forEach((item) => {
            item.date = TOOLS_DATE.translationDateToFormatDate(item.date);
          });
          this.articleList = list;
        }
      });
    },
    getChatList() {
      const uid = JSON.parse(localStorage.getItem("userInfo")).uid;
      this.$axios.post("/getChatList", { uid }).then((res) => {
        if (res.data.code === 200) {
          const list = Array.from(res.data.data);
          list.forEach((item) => {
            item.date = TOOLS_DATE.translationDateToFormatDate(item.date);
          });
          this.chatList = list;
        }
      });
    },
    handleClickNav(value) {
      this.navChoose = value;
    },
    handleClickArticleItem(id) {
      for (const item of this.articleList) {
        if (item.id === id) {
          this.dialogInfo.essay = item;
          break;
        }
      }
      this.visible.essay = true;
    },
  },
};
</script>
<style scoped lang="less">
.page {
  padding: 20px 20px 0;

  .hint {
    font-weight: 600;
  }

  .content {
    padding: 15px 0;
    .table {
      height: 70vh;
      overflow-y: auto;
    }

    .op {
      color: #2468f2;
    }

    .top {
      margin-top: 3vh;
    }
  }
}

.page {
  .top {
    display: flex;
    flex-flow: column;
    align-items: center;
    text-align: center;
    padding-bottom: 30px;
    border-bottom: #2468f2 1px solid;
  }
}

.content {
  .tab-list {
    width: 10%;
    margin: 15px 10px;

    .tab-item {
      display: flex;
      height: 80px;
      justify-content: center;
      align-items: center;
      //background-color: #2468F2;
      border-radius: 5px;
      margin-bottom: 10px;
      transition: all 0.2s;

      i {
        font-size: 25px;
        color: rgba(233, 232, 237, 1);
      }

      .title {
        font-size: 14px;
        color: rgba(0, 0, 0, 0.6);
        margin-left: 12px;
      }

      &:hover {
        background-color: rgba(83, 86, 90, 0.05);
      }
    }

    .active {
      background-color: rgba(83, 86, 90, 0.05);

      .text {
        color: rgba(57, 145, 238, 1);
      }

      .title {
        color: rgba(57, 145, 238, 1);
      }
    }
  }

  .rightBox {
    width: 90%;
    padding: 25px;

    .bottom {
      .itemList {
        display: flex;
        justify-content: space-around;
        flex-wrap: wrap;
        padding: 36px 128px;
        overflow-y: auto;
        height: 750px;

        .item {
          flex: 25%;
          display: flex;
          height: 150px;

          img {
            height: 100px;
          }

          .date {
            height: 50px;
            line-height: 80px;
          }

          .text {
          }
        }
      }
    }
  }
  .card-columns {
    padding: 25px;
    column-count: 3;
    column-gap: 1.25rem;
    display: flex;
    flex-wrap: wrap;
    padding: 36px 128px;
    overflow-y: auto;
    height: 850px;

    .card {
      break-inside: avoid;
      display: flex;
      width: 16rem;
      flex-direction: column;
      justify-content: space-around;
      margin-bottom: 1.25rem;
    }

    .card-img-top {
      flex-shrink: 1;
      width: 80%;
      text-align: center;
    }

    .card-body {
      flex-grow: 1;
      padding: 1.25rem;
    }

    .card-title {
      font-size: 1.25rem;
      margin-bottom: 0.75rem;
    }
    .card-text {
      width: 100%;
      display: -webkit-box;
      -webkit-box-orient: vertical;
      overflow: hidden;
      -webkit-line-clamp: 3;
    }
  }
  .card-list {
    column-count: 3;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    padding: 36px 128px;
    overflow-y: auto;
     overflow-x: auto;
    height: 850px;
    .card {
      display: flex;
      flex-direction: column;
      width: calc(33.33% - 10px);
      margin-bottom: 40px;
      background-color: #fff;
      border-radius: 15px;
      box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
      .card-image {
        position: relative;
        width: 100%;
        height: 120px;
        border-radius: 5px 5px 0 0;
        overflow: hidden;
        img {
          display: block;
          margin: auto;

          height: 100%;
        }
      }
      .card-content {
        padding: 25px;
         background-color: #dfecfb;
        color: #333;
          opacity: 0.5;
      }
      .card-title {
        font-size: 18px;
        font-weight: bold;
        margin-bottom: 10px;
        font-size: 1.5rem;
        margin-bottom: 0.75rem;
        color: #333;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        overflow: hidden;
        -webkit-line-clamp: 1;
      }
      .card-text {
        width: 100%;
        padding-bottom: 20px;
      }
      .success {
        background-color: #40c9ae;
        
        color: #333;
        opacity: 0.5;
      }
      .primary {
        background-color: #dfecfb;
        color: #333;
        
      }
    }
  }
}
</style>
